//
//  ViewController.m
//  数字变化动效
//
//  Created by tianlong on 2018/6/5.
//  Copyright © 2018年 tianlong. All rights reserved.
//

#import "ViewController.h"
#import "WXMagicNumber.h"
#import "WXMagicLabel.h"

@interface ViewController ()
@property (strong, nonatomic) WXMagicLabel *countLabel;
@property (assign, nonatomic) int numText;
@property (strong, nonatomic) WXMagicNumber *number;
@property (assign, nonatomic) int count;
@property (assign, nonatomic) int lastCount;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    WXMagicLabel *countLabel = [[WXMagicLabel alloc] init];
    countLabel.frame = CGRectMake(100, 100, 100, 40);
    countLabel.textColor = [UIColor blackColor];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.backgroundColor = [UIColor greenColor];
    self.countLabel = countLabel;
    [self.view addSubview:countLabel];
    self.lastCount = 0;
    
}
- (IBAction)random:(id)sender {
    self.count += 100;
    __weak typeof(self)ws = self;
    [self.countLabel setNumberTextWtihRollAniamtionFromNum:self.lastCount toNum:self.count duration:1 animationType:MagicAnimationTypeLinear progressBlock:^(CGFloat number, CGFloat percent) {
        ws.lastCount = ws.count;
        ws.countLabel.text = [NSString stringWithFormat:@"%.0f",number];
    }];
    [self.countLabel showTipLabelWithNumber:100 textColor:nil font:nil otherConfig:^(UILabel *tipLabel) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(dismissTipLabel) object:nil];
        [ws performSelector:@selector(dismissTipLabel) withObject:nil afterDelay:2];
    }];
}

- (void)dismissTipLabel {
    [self.countLabel.tipLabel removeFromSuperview];
}





@end
